# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
#   movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
#   Character.create(name: 'Luke', movie: movies.first)

STDOUT.puts 'delete all and import province & city …… '
provinces = JSON.parse(IO.read('db/province.json'))
Base::Province.delete_all
provinces.each do |pro|
  p = Base::Province.new(name_cn: pro['name'])
  p.id = pro['id']
  p.save
end
cities =JSON.parse(IO.read('db/city.json'))
Base::City.delete_all
cities.each do |city|
  c = Base::City.new(name_cn: city['name'],province_id: city['province_id'])
  c.id = city['id']
  c.save
end

STDOUT.puts 'import users'
Customer.delete_all
Base::User.delete_all
c = Customer.create(name:'上海先虑软件科技有限公司', short_name: 'xianlv', master_name: 'xyy', master_mobile: '13023208510')
Base::User.create(username: 'xyy', mobile: '13023208510', password: 'xyy123', customer_id: c.id)
Base::User.create(username: 'peter', mobile: '14782848456', password: 'peter123', customer_id: c.id)
Base::User.create(username: 'joel', mobile: '13764073233', password: 'joel123', customer_id: c.id)
Base::User.create(username: 'system', mobile: '13855633067', password: 'system123', customer_id: c.id)
